﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KaroEngine
{
    public static class Engine
    {
        public static Board currentBoard;
        public static short width = 21;
        public static short height = 20;
        public static short aiDepth = 4;
        private static MinMax minMax;

        public static void NewGame()
        {
            currentBoard = new Board();
        }

        public static void TryMove(short tileFrom, short tileTo, short tilePositionToMove)
        {
            if (Rules.IsValidMove(currentBoard, new Move(tileFrom, tileTo, tilePositionToMove), true))
            {
                Engine.currentBoard.DoMove(new Move(tileFrom, tileTo, tilePositionToMove));

                if ( tileFrom == -1 )
                    currentBoard.NumberOfConesOnBoard++;
            }
        }

        public static void DoAutoMove(ref short tileFrom, ref short tileTo, ref short tilePositionToMove)
        {
            if (minMax == null)
            {
                minMax = new MinMax();
            }

            Move move = minMax.GetBestMove();

            tileFrom = move.PositionFrom;
            tileTo = move.PositionTo;
            tilePositionToMove = move.TilePositionToMove;

            currentBoard.DoMove( move );

            if ( tileFrom == -1 )
                currentBoard.NumberOfConesOnBoard++;
        }

        public static void UndoMove(ref short tileFrom, ref short tileTo, ref short tilePositionToMove)
        {
            Move move = currentBoard.UnDoMove();

            tileFrom = move.PositionFrom;
            tileTo = move.PositionTo;
            tilePositionToMove = move.TilePositionToMove;

            if ( tileFrom == -1 )
                currentBoard.NumberOfConesOnBoard--;
        }
    }
}
